package com.wan.dao.role;

import com.wan.dao.BaseDao;
import com.wan.pojo.Role;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class RoleDaoImpl implements RoleDao{

    @Override
    public List<Role> getRoleList(Connection conn) {

        PreparedStatement pstm = null;
        ResultSet rs = null;
        ArrayList<Role> roleList = new ArrayList<Role>();
        ArrayList<Object> list = new ArrayList<Object>();
        if(conn != null) {
            String sql = "select * from smbms_role";

            Object[] params = list.toArray();

            try {
                rs = BaseDao.execute(conn, pstm, rs, sql.toString(), params);

                while(rs.next()) {
                    Role _role = new Role();
                    _role.setId(rs.getInt("id"));
                    _role.setRoleCode(rs.getString("roleCode"));
                    _role.setRoleName(rs.getString("roleName"));
                    roleList.add(_role);
                }
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }finally {
                BaseDao.closeResource(null,pstm,rs);
            }
        }
        return roleList;
    }
}
